package xin.core.jwt;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Serializable;

/**
 * <pre>
 *
 * </pre>
 * @version 1.0
 * @author lixin
 * @since 2017/11/23 9:46
 */
@Component
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint, Serializable {

    @Override
    public void commence(HttpServletRequest request,
                         HttpServletResponse response,
                         AuthenticationException authException) throws IOException {
        authException.printStackTrace();
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
    }
}